/**
 * ...
 * @author Krzysztof Rozalski
 */

package hapi.physics;
import hapi.math.Additive;
import hapi.math.Angle;
import hapi.math.MathUtil;
import hapi.math.Multiplicative;
using hapi.math.AngleFactoryMethods;

class AngularVelocity implements Additive<AngularVelocity,AngularVelocity>, implements Multiplicative<AngularVelocity,Float> {

	public var radiansPerSecond(default, null):Float;
	public var degreesPerSecond(getDegreesPerSecond, never):Float;
	
	public static function zero():AngularVelocity {
		return new AngularVelocity(0.0);
	}
	
	public function new(radiansPerSecond:Float) {
		this.radiansPerSecond = radiansPerSecond;
	}
	
	public function applyTo(angle:Angle, time:Time):Angle {
		return angle.add(rotationAfter(time));
	}
	
	public function rotationAfter(time:Time):Angle {
		return (radiansPerSecond * time.seconds).radians();
	}
	
	public function add(av:AngularVelocity):AngularVelocity {
		radiansPerSecond += av.radiansPerSecond;
		return this;
	}
	
	public function substract(av:AngularVelocity):AngularVelocity {
		radiansPerSecond -= av.radiansPerSecond;
		return this;
	}
	
	public function multiplyBy(scalar:Float):AngularVelocity {
		radiansPerSecond *= scalar;
		return this;
	}
	
	public function divideBy(scalar:Float):AngularVelocity {
		radiansPerSecond /= scalar;
		return this;
	}
	
	public function toString():String {
		return degreesPerSecond + " degrees per second";
	}
	
	public function clone():AngularVelocity {
		return new AngularVelocity(radiansPerSecond);
	}
	
	function getDegreesPerSecond() {
		return MathUtil.radToDeg(radiansPerSecond);
	}
}